<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="js/dis_control.js"></script>
<script src="js/zy_json.js"></script>
<script src="js/config.js"></script>
<script>
var logc = 0;
var latc = 0;
isSML = 0;
if(window.navigator.platform=='Win32'){
	isSML = 1;
	setstorage('simulate', '1');
}
else setstorage('simulate', '');

window.uexOnload = function(type){
	uexWindow.open('main', "0", 'main.html', "", "", "", "4");
	getInfor();
	get_usr_setting();
	setstorage('closead', '');
	setstorage('fscreen', '');
	setstorage('rn', '');
	setstorage('fn', '');
	
	if(!isSML) checkWidgetUpdate();
	
	uexWidgetOne.cbError = function(){
		uexWindow.toast('0','5','操作失败',2000);
	}
	
	setTimeout('clearTemp();', 1000);
	getAvatar();
}
function get_usr_setting()
{
	var url = home_url+ "&mod=misc&ac=user_setting";
	logs("get_usr_setting-->url="+ url);
	$.getJSON(url, function(json){
		if(json){
			logs("get_usr_setting-->json="+ JSON.stringify(json));
			var ostr = getstorage('usetting');
			//var obj = getStorJson('usetting');
			if(parseInt(json.status)<0) return;
			
			var pt1 = getstorage('portal');
			var pt2 = json.portalstatus;
			var data = JSON.stringify(json);
			setstorage('usetting',data);
			setstorage('portal',pt2);
			setstorage('ucurl',json.ucurl+"/avatar.php?&size=middle&uid=");
			setstorage('signstatus',json.signstatus);
			
			if(!ostr) setTimeout(function(){ueppscript('main', 'content1', "addflip('', 'main_forum');");}, 500);
			if(pt1!=pt2 && pt2=='0') uescript('main', "removeNode('pt')");
		}
	});
}
function getlocation(flag){
	if(!flag && latc && logc) locationCallback(latc, logc);
	else {
		if(!isSML){
			uexLocation.onChange = locationCallback;
			uexLocation.openLocation();
		}
		else{
			locationCallback('39.977539', '116.309357');
		}
	}
}
function locationCallback(lat, log){
	if(lat && log){
		logc = log;
		latc = latc;
		uexLocation.closeLocation();
		//logs('locationCallback: longitude='+log+', latitude='+lat);
        var url = login_url + "&mod=logging&action=location&longitude="+log+"&latitude="+lat;
        $.getJSON(url,function(json) {
        	if(json.status == '0'){
			}else if(json.status == '1'){
				logs('locationCallback: locate success ~');
        	}else{
        		logs('locationCallback: locate failed ~');
        	}
		});
	}
}

function getInfor(){
	var an = getstorage('appname');
	uexWidgetOne.cbGetCurrentWidgetInfo = function (opId,dataType,data){
		logs('getInfor()-->'+dataType+', '+data);
		if (dataType == 1) {
			var obj = eval('('+data+')');
			setstorage('appname',obj.name);
			setstorage('appid',obj.appId);
		}
	}
	
	if(!an) uexWidgetOne.getCurrentWidgetInfo();
	if(isSML) setstorage('appname','discuz3.0');
}

function checkWidgetUpdate(){
	var updateurl = '';
	var savePath = '';
	var appid = getstorage('appid');
	if(!appid) appid = 'appcanapp';
	var filepath2 = '/sdcard/'+appid+'.apk';
	uexDownloaderMgr.onStatus = function(opId,fileSize, percent, status){
		if(status == 0){
			var str = '下载进度：'+percent+'%';
			if(fileSize==-1) str = '下载中，请稍候...';
			uexWindow.toast('1','5', str,'');
		}else if (status == 1){
			uexWindow.closeToast();
			uexDownloaderMgr.closeDownloader('14');
			uexWidget.installApp(filepath2);
		}
		else{
			uexWindow.closeToast();
			uexWindow.toast('0','5','下载失败','2000');
			uexDownloaderMgr.closeDownloader('14');
		}
	}
	uexDownloaderMgr.cbCreateDownloader = function(opId,dataType,data){
		if(data == 0){
			logs('updateurl='+updateurl);
			uexDownloaderMgr.download('14', updateurl, filepath2, '0');
		}
		else{
			uexWindow.toast('0','5','下载失败','2000');
		}
	}
	uexWindow.cbConfirm = function ConfirmSuccess(opId, dataType, data){
		if (data == 1) {
			if(platform==0){
				uexWidget.loadApp("", "", updateurl);
			}
			else if(platform==1) {
				uexDownloaderMgr.createDownloader("14");	
			}
		}
	}
	uexWidget.cbCheckUpdate = function (opCode, dataType, jsonData){
		var obj = eval('('+jsonData+')');
		var tips = '';
		if(obj.result == 0){
			updateurl = obj.url;
			savePath = obj.name;
			var mycars=['稍后', '更新'];
			uexWindow.confirm('', '当前有新版本，是否更新?', mycars);		
		}else if(obj.result == 1){
			tips = "Current version is the newest";
		}else if(obj.result == 2){
			tips = "Unknow error";
		}else if(obj.result == 3){
			tips = "Params error";
		}
		logs('cbCheckUpdate()-->tips='+tips);
	}
	uexFileMgr.cbIsFileExistByPath = function(opCode,dataType,data){
		if(data == 1){
			uexWidget.checkUpdate();
		}
	}
	uexWidgetOne.cbGetPlatform = function(opId,dataType,data){
		platform = data;
		if(data==0){ //iphone
			uexWidget.checkUpdate();
		}else if(data==1){ //android
			uexFileMgr.isFileExistByPath('/sdcard/');
		}
		setstorage('platform', data);
	}
	uexWidgetOne.getPlatform();
}

function clearTemp(){
	var lsg = window.localStorage;
	var url1 = forum_url + "&mod=ajax&action=";
	var url2 = portal_url + "&mod=view&aid=";
	var url3 = home_url + "&mod=space&do=blog&uid=";
	for(var k in lsg){
		if(k.indexOf(url1)==0 || k.indexOf(url2)==0 || k.indexOf(url3)==0){
			logs('clearTemp-->k='+k);
			lsg.removeItem(k);
		}
	}
}

function getAvatar(){
	var url = home_url + "&mod=spacecp&ac=avatar";
	$.getJSON(url, function(json) {
		if(json && json.uc) setstorage('uc', json.uc);
	},'json', null, 'POST', '', '1', '1');
}

</script>
</html>